<?php namespace Common\Model;

use Hdphp\Model\Model;

class Brand extends Model{
	protected $table = "brand";

	protected $validate = array(
		array('bname','required','品牌名称不能为空',3,3)
	);
	protected $auto = array(
		array('LOGO','up','method',3,3)
	);

	public function up(){
		if(Q('post.LOGO')){
			$logo = Q('post.LOGO');
			return $logo;
		}
		$files = Upload::type('jpg,png')->size(1000000)->make();
		if($files){
			return $files[0]['path'];
		}else{
			if($_FILES['LOGO']['error'] != 4){
				$this->error = Upload::getError();
			}
			return '';
		}
	}

	public function addData(){
		if(!$this->create()){
			return false;
		}
		if($this->error){
			return false;
		}
		$this->add();
		return true;
	}

	public function editData(){
		if(!$this->create()){
			return false;
		}
		if($this->error){
			return false;
		}
		$this->save();
		return true;
	}
}



 ?>